// const getName = ({ firstname, lastname }) => {
//     return `${firstname} ${lastname}`
// }

// console.log(getName({ firstname: 'lucas', lastname: 35 }));

interface IName {
    firstname: string,
    lastname: string
}
// 写法一
// const getName = ({ firstname, lastname }: IName): string => {
//     return `${firstname} ${lastname}`
// }
// 写法二
// const getName = ({ firstname, lastname }: { firstname:string, lastname:string }): string => {
//     return `${firstname} ${lastname}`
// }

// console.log(getName({ firstname: 'lucas', lastname: 'liang' }));

//===================================================================================
interface Ifood {
    apple: string,
    banana: string,
    orange?: 'orange',
    readonly juzi: string,
    [props: string]: any // 索引签名，props是自定义的名字，这样可以任意添加属性
}

let food: Ifood = {
    apple: 'apple',
    banana: 'banana',
    juzi: '橘子',
    lizhi: '荔枝',
}

// food.juzi='test' //报错


interface AddFunc {
    (num1: number, num2: number): number
}
// 等于下面 这种【类型别名】写法
type AddFunc1 = (num1: number, num2: number) => number

// const add: AddFunc = (num1, num2) => num1 + num2
const add: AddFunc1 = (num1, num2) => num1 + num2
// console.log(add(1, 4));
//===================================================================================
//继承
interface Vegetables {
    color: string
}

interface ab extends Vegetables {
    num: number
}

let tamato: ab = {
    color: 'yellow',
    num: 34
}
//====================================
interface Counter {
    (): void,
    count: number
}

const getCounter = (): Counter => {
    const c = () => { c.count++ }
    c.count = 0
    return c
}
const counter: Counter = getCounter();
counter();
console.log(counter.count);
counter();
console.log(counter.count);
counter();
console.log(counter.count);
//====================================
// 接口继承
interface Pen{
    width:string
}
interface Pen2{
    height:number
}

interface MyPen extends Pen,Pen2{
    color:string
}

// let my_pen:MyPen; // 写法1
let my_pen=<MyPen>{}// 写法2
my_pen={width:'22px',height:11,color:'red'}
//====================================
interface Counterr {
    (start: number): string;
    interval: number;
    reset(): void;
}

function getCounterr(): Counterr {
    let counter = <Counterr>function (start: number) { };
    counter.interval = 123;
    counter.reset = function () { };
    return counter;
}

let cc = getCounterr();
cc(10);
cc.reset();
cc.interval = 5.0;
//====================================